//
//  CommonTableViewCell.m
//  YunDongGym
//
//  Created by lqq on 2018/4/18.
//  Copyright © 2018年 lqq. All rights reserved.
//

#import "CommonTableViewCell.h"

@interface CommonTableViewCell ()
@property (nonatomic, strong) UIImageView *arrowImageView;
@end

@implementation CommonTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self configUI];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self configUI];
    }
    return self;
}


- (UILabel *)leftLabel
{
    if (_leftLabel == nil) {
        _leftLabel = [[UILabel alloc] init];
        _leftLabel.textColor = HEXColor(@"333333");
        _leftLabel.font = RegularFont(14);
    }
    return _leftLabel;
}

- (UILabel *)rightLabel
{
    if (_rightLabel == nil) {
        _rightLabel = [[UILabel alloc] init];
        _rightLabel.textColor = HEXColor(@"4A4A4A");
        _rightLabel.font = RegularFont(14);
        _rightLabel.numberOfLines = 0;
        _rightLabel.textAlignment = NSTextAlignmentRight;
    }
    return _rightLabel;
}

- (UIImageView *)arrowImageView
{
    if (_arrowImageView == nil) {
        _arrowImageView = [[UIImageView alloc] init];
        _arrowImageView.image = IMG_NAME(@"ic_more");
    }
    return _arrowImageView;
}

- (UIView *)bottomLineView
{
    if (_bottomLineView == nil ) {
        _bottomLineView = [[UIView alloc] init];
        _bottomLineView.backgroundColor = HEXColor(@"E5E5E5");
    }
    return _bottomLineView;
}


- (void)configUI
{
    [self.contentView addSubview:self.leftLabel];
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(20);
        make.centerY.equalTo(self.contentView);
    }];
    
    
    [self.contentView addSubview:self.arrowImageView];
    [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-20);
        make.centerY.equalTo(self.contentView);
        make.height.equalTo(@(10));
        make.width.equalTo(@(6));
    }];
    
    [self.contentView addSubview:self.rightLabel];
    [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-33);
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(140);
    }];
    //先隐藏
    self.rightLabel.hidden = YES;
    
    [self.contentView addSubview:self.bottomLineView];
    [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.contentView);
        make.height.equalTo(@(kOnePX));
    }];
    
}

- (void)prepareForReuse
{
    [super prepareForReuse];
    self.showStyle = CommonTableViewShowStyleArrow;
}

- (void)setShowStyle:(CommonTableViewShowStyle)showStyle
{
    _showStyle = showStyle;
    switch (showStyle) {
        case CommonTableViewShowStyleArrow:
        {
            self.arrowImageView.hidden = NO;
            self.rightLabel.hidden = YES;
        }
            break;
            
        case CommonTableViewShowStyleArrow_RightText:
        {
            self.arrowImageView.hidden = NO;
            self.rightLabel.hidden = NO;
            [self.rightLabel mas_updateConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(self.contentView).offset(-33);
                make.centerY.equalTo(self.contentView);
            }];
        }
            break;
        case CommonTableViewShowStyleRightText:
        {
            self.arrowImageView.hidden = YES;
            self.rightLabel.hidden = NO;
            [self.rightLabel mas_updateConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(self.contentView).offset(-20);
                make.centerY.equalTo(self.contentView);
            }];
        }
            break;

            
        default:
        {
            self.arrowImageView.hidden = YES;
            self.rightLabel.hidden = YES;
        }
            break;
    }
}


@end
